package org.example.managere.repository.feibiao;

import org.example.managere.entity.feibiao.AmArchivesBase;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;
 
@Repository
public interface AmArchivesBaseRepository extends JpaRepository<AmArchivesBase, String> {
    
    /**
     * 根据电机型号查询电机信息
     */
    List<AmArchivesBase> findByMotorTypeContaining(String motorType);
    
    /**
     * 根据厂商名称查询电机信息
     */
    List<AmArchivesBase> findByManufacturerContaining(String manufacturer);
    
    /**
     * 根据关键字在电机ID、电机型号或厂商名称中进行模糊搜索
     */
    @Query("SELECT a FROM AmArchivesBase a WHERE a.motorId LIKE %:keyword% OR a.motorType LIKE %:keyword% OR a.manufacturer LIKE %:keyword%")
    List<AmArchivesBase> searchByKeyword(String keyword);
    
    /**
     * 根据关键字在电机ID、电机型号或厂商名称中进行模糊搜索（分页）
     */
    @Query("SELECT a FROM AmArchivesBase a WHERE a.motorId LIKE %:keyword% OR a.motorType LIKE %:keyword% OR a.manufacturer LIKE %:keyword%")
    Page<AmArchivesBase> searchByKeywordPaged(String keyword, Pageable pageable);
} 